// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'font-awesome/css/font-awesome.min.css'
import 'material-design-icons-iconfont/dist/material-design-icons.css'
import Vuetify from 'vuetify'
import 'vuetify/dist/vuetify.min.css'
import zhHans from 'vuetify/es5/locale/zh-Hans'
import ECharts from 'vue-echarts'
import axios from 'axios'
import qs from 'qs'
import VueCookie from 'vue-cookie'
import 'babel-polyfill'

Vue.use(VueCookie)
Vue.prototype.$ajax = axios
Vue.component('v-chart', ECharts)
Vue.use(Vuetify, {
  lang: {
    locales: { zhHans },
    current: 'zhHans'
  }
})
Vue.config.productionTip = false
axios.defaults.validateStatus = (status) => {
  return status >= 100 // 默认的
}
axios.interceptors.request.use(function (config) {
  if (config.method !== 'get') {
    config.data = qs.stringify(config.data)
  }
  config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
  let token = window.sessionStorage.getItem('TOKEN')
  if (token) {
    config.headers.common['Authorization'] = 'Bearer ' + token
  }
  return config
}, function (error) {
  return Promise.reject(error)
})

// 添加响应拦截器
axios.interceptors.response.use((response) => {
  // 对响应数据做点什么
  return response
}, (error) => {
  // 对响应错误做点什么
  return Promise.reject(error)
})
// 注册
Vue.filter('showMoneyFilter', function (value) {
  return (value * 1).toFixed(2)
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
